<template>
  <p-card :bordered="false" :class="'cust-erp-sub-tab'">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <p-form layout="inline" @keyup.enter.native="searchQuery">
        <p-row :gutter="24">
          <p-col :span="8">
            <p-form-item label="产品编码">
              <p-input-search
                placeholder="请输入产品编码"
                v-model="mcode"
                @search="onSearch"
              ></p-input-search>
            </p-form-item>
          </p-col>
        </p-row>
      </p-form>
    </div>
    <!-- 查询区域-END -->
    <p-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      :scroll="tableScroll"
      :columns="defColumns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      :rowSelection="{selectedRowKeys: selectedRowKeys,onChange: onSelectChange,type:'radio',}"
      @change="handleTableChange"
    >
    </p-table>
  </p-card>
</template>
<script>
import { postAction, getAction, deleteAction } from "@/api/manage";

export default {
  props:['link'],
    data(){
        return {
        mcode:'',
        selectedRowKeys: [],
        selectUserRows: [],
        selectUserIds: [],
        dataSource:[],
        defColumns: [
        {
          title: "序号",
          dataIndex: "",
          key: "rowIndex",
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          },
        },
        {
          title: "产品编码",
          align: "center",
          dataIndex: "mcode",
        },
        {
          title: "产品名称",
          align: "center",
          dataIndex: "mname",
        },
        {
          title: "产品单位",
          align: "center",
          dataIndex: "units",
        },
        {
          title: "产品描述",
          align: "center",
          dataIndex: "mexplain",
        },
        {
          title:"规格型号",
          align:'center',
          dataIndex:"sprc"
        }
        
      ],
        url:{
            // 非物料类型信息分页查询
            list:"/basic-business/auto/baCpinfoMain/queryNotMaterielPage"
        },
        ipagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ["10", "20", "50"],
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条";
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0,
      },
        }
    },
    mounted(){
      if(this.link){
        this.url.list=this.link
      }else{
        this.url.list="/basic-business/auto/baCpinfoMain/queryNotMaterielPage"
      }
        this.loadData()
        console.log(this.url.list)
    },
    methods:{
        loadData(){
            let obj={
                pageNo : this.ipagination.current,
                pageSize : this.ipagination.pageSize,
                limit :this.ipagination.pageSize,
                keyword:this.mcode
            }
            getAction(this.url.list,obj).then(res=>{
                if(res.code==0){
                    this.dataSource=res.data.records
                    this.ipagination.total=res.data.total
                    console.log(res.data.records)
                }else{
                    this.$message.error(res.msg)
                }
            })
        },
        onSearch(){
            this.loadData()
        },
        handleTableChange(pagination){
            this.ipagination.current=pagination.current
            this.ipagination.pageSize=pagination.pageSize
            this.loadData()
        },
        onSelectChange (selectedRowKeys, selectionRows) {
            this.selectedRowKeys = selectedRowKeys
            this.selectionRows = selectionRows
            this.selectedData = selectionRows
            this.$emit('getNumber',selectionRows)
        }
      }
    
}
</script>>